import React, { useState } from 'react'
import './GoodsImage.css';

export default function GoodsImage() {
  //声明状态
  let [index, setIndex] = useState(0);
  //声明变量
  let imageArr = [
    //alt + shift + ↓
    "/goods/1.jpg",
    "/goods/2.jpg",
    "/goods/3.jpg",
    "/goods/4.jpg",
    "/goods/5.jpg",
  ]

  return (
    <div className='goods-image'>
      <div className="big-image">
        <img src={imageArr[index]} alt="" />
      </div>
      <div className="small-images">
        {
          imageArr.map((item, ind) => {
            return <div 
                      className="item" 
                      key={ind}
                      //绑定鼠标移入事件 
                      onMouseOver={() => {
                        //修改 index 的状态值
                        setIndex(ind);
                      }}
                      >
                      <img className={ind === index ? 'active' : ''} src={item} alt='' />
                    </div>
          })
        }
        
      </div>
    </div>
  )
}
